<#--
/****************************************************
 * Description: 权限设置页面
 * Copyright:   Copyright (c) 2013
 * Company:     beiwaionline
 * @author      bfsu
 * @version     1.0
 * @see
	HISTORY
    *  2013-08-08 bfsu Create File
**************************************************/
-->
<#include "/view/templates/ace/ace-inc.ftl">
<script>
	function checkSelect(treeNodePId){
		var parentSec = document.getElementById(treeNodePId);
		if(parentSec.checked){
			var childSecs = getElementsByClassName(treeNodePId);
			for(var i=0;i<childSecs.length;i++){
				childSecs[i].checked = true;
			}
		}else{
			var childSecs = getElementsByClassName(treeNodePId);
			for(var i=0;i<childSecs.length;i++){
				childSecs[i].checked = false;
			}
		}
	}
	function checkSelect1(treeNodePId,treeNodeCId){
		var parentSec = document.getElementById(treeNodePId);
		var childSec = document.getElementById(treeNodePId+"_"+treeNodeCId);
		if(!childSec.checked){
			parentSec.checked = false;
		}else{
			var childSecs = getElementsByClassName(treeNodePId);
			var count = 0;
			for(var i=0;i<childSecs.length;i++){
				if(childSecs[i].checked == true){
					count++;
				}
			}
			if(count == childSecs.length){
				parentSec.checked = true;
			}
		}
	}
	function getElementsByClassName(className) {
		var classElements = [],allElements = document.getElementsByTagName('*');
		for (var i=0; i< allElements.length; i++ ){
			 if (allElements[i].className == className ) {
			 	classElements[classElements.length] = allElements[i];
			 }
		}
		return classElements;
	}
	$(function(){
		$(":input").each(function(){
			if($(this).val()=='yes'){
				document.getElementById($(this).prop("class")).checked = true;
			};
		});
	});
</script>
<@input url="${base}/components/security/role/savepri">
	<input type="hidden" name="roleId" value="${roleid!''}"/>
	<div class="table-responsive">
		<table class='table'>
			<tbody>
		<#list treeNodeList?sort_by('text') as treeNode>
			<tr>
				<td >
				    ${treeNode.text!''}
			    </td>
			</tr>
			<#if (treeNode.nodes?exists && treeNode.nodes?size gt 0)>
				<#list treeNode.nodes?sort_by('text') as treeNode1>
					<tr>
						<td>
							<input type="hidden" class="${treeNode1.id!''}" value="${treeNode1.checked?string('yes', 'no')}"/>
							&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="${treeNode1.id!''}" onclick="checkSelect('${treeNode1.id!''}')" >
							${treeNode1.text}
				        </td>
					</tr>
					<#if (treeNode1.nodes?exists && treeNode1.nodes?size>0)>
						<#list treeNode1.nodes?sort_by('text') as treeNode2>
							<tr>
								<td>
									<input type="hidden" name="${treeNode1.id!''}" class="${treeNode1.id!''}_${treeNode2.id!''}" value="${treeNode2.checked?string('yes', 'no')}"/>
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="${treeNode1.id!''}_${treeNode2.id!''}" name="codes" class="${treeNode1.id!''}" value="${treeNode1.id!''}===${treeNode2.id!''}" onclick="checkSelect1('${treeNode1.id!''}','${treeNode2.id!''}')" >
									${treeNode2.text}
						        </td>
							</tr>
						</#list>
					</#if>
				</#list>
			</#if>
		</#list>
			</tbody>
		</table>
	</div>
</@input>


